package com.chinanet.netelementmodel;


import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.pon.HW_Socket_AttrsIn;
import com.chinanet.utils.pon.OperationType;
import com.chinanet.utils.pon.ZXGetFinalResult;
import com.chinanet.utils.pon.ZX_SocketClient;

import java.util.HashMap;
import java.util.Map;

/**
 * ZX_Query_UNIPORT_INFOImp
 * 中兴PON网管-查看OUN状态/最后一次下线原因
 * @author xuzhi
 *
 */
public class ZX_Query_ONU_STATEImp implements WorkInterFace {

	public String getName() {
		return "中兴PON网管-查看OUN状态/最后一次下线原因";
	}

	public String getDesciption() {
		return "";
	}

	public int getVersion() {
		return 0;
	}

	public Attr[] getInAttrs() {
		Attr[] in = new Attr[4];
//		in[0] = new Attr("Port", "端口号", AttrType.TYPE_String, true);
		in[0] = new Attr("OLTID", "OLT的ID", AttrType.TYPE_String, true);
		in[1] = new Attr("PONID", "PON的ID，如：查询OLT设备上0框4槽1端口的光模块信息，PONID为NA-0-4-1", AttrType.TYPE_String, true);
		in[2] = new Attr("ONUIDTYPE", "ONU标识类型", AttrType.TYPE_String, true);
		in[3] = new Attr("ONUID", "ONU标识，可以按ONU_NAME/MAC/LOID/ONU_NUMBER取值，用于唯一标识PON口的ONU", AttrType.TYPE_String, true);
		return in;
	}

	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[3];
		out[0] = new Attr("flag", "操作是否成功，1：成功，0：失败", AttrType.TYPE_Int, true);
		out[1] = new Attr("onustate","ONU运行状态。 UP：在线 Power-Off：掉电 LOS：断纤 other：其它", AttrType.TYPE_String, true);
		out[2] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
		return out;
	}

	public Map<String, Object> init(Map<String, Object> data) {
		Map<String, Object> inmap = new HashMap<String, Object>();
		Map<String, Object> outmap = new HashMap<String, Object>();
		String ip ="134.103.235.44";
		int port = 9820;
		ZX_SocketClient hclient = new ZX_SocketClient(ip, port);
		HW_Socket_AttrsIn attrsin = new HW_Socket_AttrsIn();
		ZXGetFinalResult result = new ZXGetFinalResult();
		attrsin.setOLTID((String) data.get("OLTID"));
		attrsin.setPONID((String) data.get("PONID"));
		attrsin.setONUIDTYPE((String) data.get("ONUIDTYPE"));
		attrsin.setONUID((String) data.get("ONUID"));
		inmap = hclient.init(attrsin,
				OperationType.TYPE_Query_ONU_STATE);

		boolean flag = (Boolean) inmap.get("flag");
		String onustate="";
		try {
			onustate =result.returnOUNstate((String) inmap.get("ownlog"));
		} catch (Exception e) {
			onustate = "读取出错";
		}
		if (flag) {
			outmap.put("flag", 1);
			outmap.put("onustate",onustate);
			outmap.put("log", inmap.get("log"));
		} else {
			outmap.put("flag", 0);
			outmap.put("onustate",onustate);
			outmap.put("log", inmap.get("log"));

		}


		return outmap;
	}

}
